package com.nft.collection.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nft.collection.param.CancelPayParam;
import com.nft.collection.param.CollectionCancelResaleParam;
import com.nft.collection.param.CollectionGiveParam;
import com.nft.collection.param.CollectionGiveRecordQueryCondParam;
import com.nft.collection.param.CollectionQueryCondParam;
import com.nft.collection.param.CollectionResaleParam;
import com.nft.collection.param.ConfirmPayParam;
import com.nft.collection.param.LatestCollectionCreateOrderParam;
import com.nft.collection.param.MemberHoldCollectionQueryCondParam;
import com.nft.collection.param.PayOrderQueryCondParam;
import com.nft.collection.param.ResaleCollectionCreateOrderParam;
import com.nft.collection.param.ResaleCollectionQueryCondParam;
import com.nft.collection.service.CollectionService;
import com.nft.collection.vo.CollectionReceiverInfoVO;
import com.nft.collection.vo.GroupByDateCollectionVO;
import com.nft.collection.vo.IssuedCollectionActionLogVO;
import com.nft.collection.vo.LatestCollectionDetailVO;
import com.nft.collection.vo.LatestCollectionVO;
import com.nft.collection.vo.MyGiveRecordVO;
import com.nft.collection.vo.MyHoldCollectionDetailVO;
import com.nft.collection.vo.MyHoldCollectionVO;
import com.nft.collection.vo.MyPayOrderDetailVO;
import com.nft.collection.vo.MyPayOrderVO;
import com.nft.collection.vo.MyResaleCollectionDetailVO;
import com.nft.collection.vo.MyResaleCollectionVO;
import com.nft.collection.vo.MySoldCollectionVO;
import com.nft.collection.vo.ResaleCollectionDetailVO;
import com.nft.collection.vo.ResaleCollectionVO;
import com.nft.common.vo.PageResult;
import com.nft.common.vo.Result;

import cn.dev33.satoken.stp.StpUtil;

@RestController
@RequestMapping("/collection")
public class CollectionController {

	@Autowired
	private CollectionService collectionService;

	@GetMapping("/findIssuedCollectionActionLog")
	public Result<List<IssuedCollectionActionLogVO>> findIssuedCollectionActionLog(String issuedCollectionId) {
		return Result.success(collectionService.findIssuedCollectionActionLog(issuedCollectionId));
	}

	@GetMapping("/findMyPayOrderDetail")
	public Result<MyPayOrderDetailVO> findMyPayOrderDetail(String id) {
		return Result.success(collectionService.findMyPayOrderDetail(id));
	}

	@GetMapping("/findMyPayOrderByPage")
	public Result<PageResult<MyPayOrderVO>> findMyPayOrderByPage(PayOrderQueryCondParam param) {
		param.setMemberId(StpUtil.getLoginIdAsString());
		return Result.success(collectionService.findMyPayOrderByPage(param));
	}

	@PostMapping("/cancelPay")
	public Result<String> cancelPay(CancelPayParam param) {
		param.setMemberId(StpUtil.getLoginIdAsString());
		collectionService.cancelPay(param);
		return Result.success();
	}

	@PostMapping("/confirmPay")
	public Result<String> confirmPay(ConfirmPayParam param) {
		param.setMemberId(StpUtil.getLoginIdAsString());
		collectionService.confirmPay(param);
		return Result.success();
	}

	@PostMapping("/resaleCollectionCreateOrder")
	public Result<String> resaleCollectionCreateOrder(ResaleCollectionCreateOrderParam param) {
		param.setMemberId(StpUtil.getLoginIdAsString());
		String orderId = collectionService.resaleCollectionCreateOrder(param);
		return Result.success().setData(orderId);
	}

	@PostMapping("/latestCollectionCreateOrder")
	public Result<String> latestCollectionCreateOrder(LatestCollectionCreateOrderParam param) {
		param.setMemberId(StpUtil.getLoginIdAsString());
		String orderId = collectionService.latestCollectionCreateOrder(param);
		return Result.success().setData(orderId);
	}

	@GetMapping("/findMyGiveRecordByPage")
	public Result<PageResult<MyGiveRecordVO>> findMyGiveRecordByPage(CollectionGiveRecordQueryCondParam param) {
		param.setMemberId(StpUtil.getLoginIdAsString());
		return Result.success(collectionService.findMyGiveRecordByPage(param));
	}

	@GetMapping("/getCollectionReceiverInfo")
	public Result<CollectionReceiverInfoVO> getCollectionReceiverInfo(String giveToAccount) {
		return Result.success(collectionService.getCollectionReceiverInfo(giveToAccount, StpUtil.getLoginIdAsString()));
	}

	@PostMapping("/cancelResale")
	public Result<String> cancelResale(CollectionCancelResaleParam param) {
		param.setMemberId(StpUtil.getLoginIdAsString());
		collectionService.cancelResale(param);
		return Result.success();
	}

	@PostMapping("/collectionResale")
	public Result<String> collectionResale(CollectionResaleParam param) {
		param.setMemberId(StpUtil.getLoginIdAsString());
		collectionService.collectionResale(param);
		return Result.success();
	}

	@PostMapping("/collectionGive")
	public Result<String> collectionGive(CollectionGiveParam param) {
		param.setMemberId(StpUtil.getLoginIdAsString());
		collectionService.collectionGive(param);
		return Result.success();
	}

	@GetMapping("/findResaleCollectionDetail")
	public Result<ResaleCollectionDetailVO> findResaleCollectionDetail(String id) {
		return Result.success(collectionService.findResaleCollectionDetail(id));
	}

	@GetMapping("/findMyResaleCollectionDetail")
	public Result<MyResaleCollectionDetailVO> findMyResaleCollectionDetail(String id) {
		return Result.success(collectionService.findMyResaleCollectionDetail(id, StpUtil.getLoginIdAsString()));
	}

	@GetMapping("/findMyHoldCollectionDetail")
	public Result<MyHoldCollectionDetailVO> findMyHoldCollectionDetail(String id) {
		return Result.success(collectionService.findMyHoldCollectionDetail(id, StpUtil.getLoginIdAsString()));
	}

	@GetMapping("/findMySoldCollectionByPage")
	public Result<PageResult<MySoldCollectionVO>> findMySoldCollectionByPage(ResaleCollectionQueryCondParam param) {
		param.setMemberId(StpUtil.getLoginIdAsString());
		return Result.success(collectionService.findMySoldCollectionByPage(param));
	}

	@GetMapping("/findMyHoldCollectionByPage")
	public Result<PageResult<MyHoldCollectionVO>> findMyHoldCollectionByPage(MemberHoldCollectionQueryCondParam param) {
		param.setMemberId(StpUtil.getLoginIdAsString());
		return Result.success(collectionService.findMyHoldCollectionByPage(param));
	}

	@GetMapping("/findResaleCollectionByPage")
	public Result<PageResult<ResaleCollectionVO>> findResaleCollectionByPage(ResaleCollectionQueryCondParam param) {
		return Result.success(collectionService.findResaleCollectionByPage(param));
	}

	@GetMapping("/findMyResaleCollectionByPage")
	public Result<PageResult<MyResaleCollectionVO>> findMyResaleCollectionByPage(ResaleCollectionQueryCondParam param) {
		param.setMemberId(StpUtil.getLoginIdAsString());
		return Result.success(collectionService.findMyResaleCollectionByPage(param));
	}

	@GetMapping("/findLatestCollectionDetailById")
	public Result<LatestCollectionDetailVO> findLatestCollectionDetailById(String id) {
		return Result.success(collectionService.findLatestCollectionDetailById(id));
	}

	@GetMapping("/findLatestCollectionByPage")
	public Result<PageResult<LatestCollectionVO>> findLatestCollectionByPage(CollectionQueryCondParam param) {
		return Result.success(collectionService.findLatestCollectionByPage(param));
	}

	@GetMapping("/findForSaleCollection")
	public Result<List<GroupByDateCollectionVO>> findForSaleCollection() {
		return Result.success(collectionService.findForSaleCollection());
	}

}
